home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_1.lha / 6_1 / 6_1b.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  435b  |  18 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / exercise 6.1
  6. / string concatenation operator
  7. tring operator+(string& st1, string& st2)
  8.  
  9.    char *s1 = st1.p->s;
  10.    char *s2 = st2.p->s;
  11.    int s1len = strlen(s1);
  12.    char *ns = new char[s1len + strlen(s2) + 1];
  13.    strcpy(ns, s1);
  14.    strcpy(ns + s1len, s2);
  15.    string st(ns);
  16.    return st;
  17.  
  18.